<?php
if (!defined('CURRENT_PATH')){
	die('Hacking attempt');
	}
$page=isset($_GET[page])?intval($_GET[page]):1;
$gm=spClass(guest);
if($_REQUEST['act']&&$_REQUEST['act']=='view'){
if(empty($_REQUEST['id'])){
		$this->error("必须指定留言的ID");
	}else{
		$id=intval($_REQUEST['id']);	
	}
	$res=$gm->find($conditions=array('id'=>$id));	
	$xml = simplexml_load_file("http://www.youdao.com/smartresult-xml/search.s?type=ip&q=".$res['ip']);
	@$res['ip']=$res['ip'].'/'.$xml->product->location;
	$this->res=$res; 
$this->display('management/guestmessageview.html');
$gm->updateField($conditions=array('id'=>$id),'status','1');			
}else if($_REQUEST['act']&&$_REQUEST['act']=='passgen'){
	if(empty($_REQUEST['id'])){
		echo'{"result":"error"}';
		header("Content-Type:text/html;charset=utf-8");
		echo'<script> alert("必须指定用户ID！");window.history.go(-1);</script>';
	}else{
		$id=intval($_REQUEST['id']);
		include(APP_PATH."/controller/String.class.php");
        $randval = String::rand_string(6, 0);
		$gm->updateField($conditions=array('id'=>$id),'pass',$randval);								//更新密码
		header("Content-Type:text/html;charset=utf-8");
		echo'<script> alert("恭喜，添加密码成功！");window.history.go(-1);</script>';
	}
}else{
$res=$gm->spPager($this->spArgs('page', $page),10)->findAll($conditions,$sort='time desc',$fields=''); 
//foreach($res as $id=>$v){
//	$xml = simplexml_load_file("http://www.youdao.com/smartresult-xml/search.s?type=ip&q=".$v['ip']);
//	@$res[$id]['ip']=$v['ip'].'/'.$xml->product->location; 
//	}
$this->res=$res;
$this->pager=$gm->spPager()->getPager();
$this->display('management/guestmessage.html');		
}